package com.offcn.controller;

import com.offcn.bean.Evaluate;
import com.offcn.service.EvaluateService;
import com.offcn.utils.OAResult;
import com.offcn.utils.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/evaluate")
public class EvaluateController {

    @Autowired
    private EvaluateService evaluateService;

    @RequestMapping("/{page}")
    public String forwardPage(@PathVariable String page, Integer uid, Model model) {
        model.addAttribute("uid",uid);
        return "evaluate/"+page;
    }

    @RequestMapping("/evaluateById")
    @ResponseBody
    public Evaluate evaluateById(int bid){
        return evaluateService.evaluateById(bid);
    }

    @Value("${pageSize}")
    private Integer pageSize;
    @RequestMapping("/getAllEvaluate")
    @ResponseBody
    public PageView<Evaluate> getAllEvaluate(@RequestParam(defaultValue = "1") int currentPage,
                                             @RequestParam(defaultValue = "") String econtent){
        return evaluateService.getAllEvaluate(currentPage,pageSize,econtent);
    }

    @RequestMapping("/deleteEvaluate")
    @ResponseBody
    public OAResult deleteEvaluate(int eid){
        return evaluateService.deleteEvaluate(eid);
    }
}
